import java.awt.*;
import java.util.*;
import java.util.List;

public class CardList {
    public static final String[] SUITS = {"♠", "♥", "♣", "♦"};//花色一般不会改变，所以可以加static


    // 买一副牌
    private static List<Card> buyDeck() {
        List<Card> deck = new ArrayList<>(52);
        for (int i = 0; i < SUITS.length; i++) {
            for (int j = 1; j <= 13; j++) {
                //1
/*                String suit = SUITS[i];
                int rank = j;
                Card card = new Card();
                card.rank = rank;
                card.suit = suit;*/
                //2
/*                String suit = SUITS[i];
                int rank = j;
                Card card = new Card(suit,rank);*/
                Card card = new Card(SUITS[i],j);
                deck.add(card);
            }
        }
        return deck;
    }

    //交换牌面
    private static void swap(List<Card> deck, int i, int j) {
        Card t = deck.get(i);
        deck.set(i, deck.get(j));
        deck.set(j, t);
    }

    //洗牌
    private static void shuffle(List<Card> deck) {
        Random random = new Random();
        //倒着遍历，50的时候生成的就是1~49的随机数
        for (int i = deck.size() - 1; i > 0; i--) {
            int r = random.nextInt(i);
            swap(deck, i, r);
        }
    }

    public static void main(String[] args) {
        List<Card> deck = buyDeck();
        System.out.println("刚买回来的牌:");
        System.out.println(deck);
        shuffle(deck);
        System.out.println("洗过的牌:");
        System.out.println(deck);
        // 总共有三个人，每个人轮流抓 5 张牌
        //每轮一人拿一张牌
        List<Card> hand1 = new ArrayList<>();
        List<Card> hand2 = new ArrayList<>();
        List<Card> hand3 = new ArrayList<>();
        List<List<Card>> hands = new ArrayList<>();
        hands.add(hand1);
        hands.add(hand2);
        hands.add(hand3);
        for (int i = 0; i < 5; i++) {
            for (int j = 0; j < 3; j++) {
                //hands.get(j).add(deck.remove(0));
                hands.get(j).add(deck.get(j));
            }
        }
        System.out.println("剩余的牌:");
        System.out.println(deck);
        System.out.println("A 手中的牌:");
        System.out.println(hands.get(0));
        System.out.println("B 手中的牌:");
        System.out.println(hands.get(1));
        System.out.println("C 手中的牌:");
        System.out.println(hands.get(2));

    }


}